﻿using System;
using System.Collections.Generic;
using System.Windows.Data;
using System.Windows.Media;


namespace HobSoft.SoccerBet2014.Client.Common
{
    public class LeagueColorConverter : IValueConverter
    {
        protected static Dictionary<string, string> ColorsSetting = new Dictionary<string, string>()
        {
            {"英超", "c1a693"},
            {"亚冠", "67b15a"},
            {"西甲", "890044"},
            {"default","890044"}
        };

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var league = value as string;
            if (league == null)
                return Colors.Transparent;

            var colorcode = ColorsSetting["default"];
            if (ColorsSetting.ContainsKey(league))
                colorcode = ColorsSetting[league];

            var colorVal = int.Parse(colorcode, System.Globalization.NumberStyles.HexNumber);

            Color color = Color.FromRgb(
                  System.Convert.ToByte((colorVal >> 16) & 255)
                , System.Convert.ToByte((colorVal >> 8) & 255)
                , System.Convert.ToByte((colorVal >> 0) & 255));
            SolidColorBrush brush = new SolidColorBrush(color);
            return brush;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

